package edu.testdemo.utils;

import edu.nf.SQLExecutor;

public class SQLExecutorFactory {

    private static ThreadLocal<SQLExecutor> local = new ThreadLocal<>();

    private SQLExecutorFactory(){}

    /**
     * 获取本地线程副本的SQLExecuter
     * @return
     */
    public static SQLExecutor getCurrentSQLExecutor(){
        if (local.get()==null){
            local.set(new SQLExecutor(ConnUtil.getConnection()));
        }
        return local.get();
    }

    /**
     * 新建SQLExecuter
     * @return
     */
    public static SQLExecutor getSQLExecutor(){
        return new SQLExecutor(ConnUtil.getConnection());
    }

    /**
     * 移除本地线程副本
     */
    public static void remvoeThreadLocal(){
        local.remove();
    }
}
